package com.agan.aganalgorithm.titles;

import java.util.Collections;
import java.util.List;

/**
 * @author agan
 * @ClassName Demo
 * @Description
 *
 * 给定两个字符串str1和str2,输出两个字符串的最长公共子串，如果最长公共子串为空，输出-1
 *
 * 示例1
 * 输入
 * "1AB2345CD","12345EF"
 * 输出
 * "2345"
 *
 *
 * @Date 2021/4/8 8:08 下午
 **/
public class Demo {

    public static void main(String[] args) {
        String strOne = "1AB2345CD";
        String strTwo = "12345EF";
        String result = getPublicStrings(strOne,strTwo);
        System.out.println(result);

    }

    public static String getPublicStrings(String strOne,String strTwo){
        StringBuffer sbf = new StringBuffer();

        Boolean isHave = false;

        int oneLegth = strOne.length();


        for(int i=0; i< strOne.length(); i++){
            for(int j=0; j< strTwo.length(); j++){
                if(strOne.charAt(i) == strTwo.charAt(j) ){

                    System.out.println("a"+strOne.charAt(i));
                    sbf.append(strOne.charAt(i));
                    isHave = true;
                }
                break;

            }
        }


        if(!isHave){
            return "-1";
        }

        return sbf.toString();

    }


}
